import 'package:flutter/material.dart';

class ProgressDemo extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _ProgressDemoState();
  }
}

class _ProgressDemoState extends State<ProgressDemo> with SingleTickerProviderStateMixin {
  AnimationController _animationController;

  @override
  void initState() {
    _animationController = AnimationController(vsync: this, duration: Duration(seconds: 3));
    _animationController.forward();
    _animationController.addListener(() {
      setState(() {
      });
    });

    super.initState();
  }

  @override
  void dispose() {
    _animationController.dispose();

    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('进度条例子'),
      ),
      body: SingleChildScrollView(
        child: Column(
          children: <Widget>[
            // 动画
            Padding(
              padding: const EdgeInsets.all(16),
              child: LinearProgressIndicator(
                value: _animationController.value,
                backgroundColor: Colors.grey[200],
                valueColor: ColorTween(begin: Colors.grey, end: Colors.blue).animate(_animationController),
              ),
            ),

            // 宽高不等
            SizedBox(
              height: 100,
              width: 130,
              child: CircularProgressIndicator(
                backgroundColor: Colors.grey[200],
                valueColor: AlwaysStoppedAnimation(Colors.blue),
                value: .7,
              ),
            ),

            // 仅作为留白间隔
            Padding(padding: const EdgeInsets.only(top: 10)),

            // 线性进度条高度指定为3
            SizedBox(
              height: 3,
              child: LinearProgressIndicator(
                backgroundColor: Colors.grey[200],
                valueColor: AlwaysStoppedAnimation(Colors.blue),
                value: .5,
              ),
            ),

            // 仅作为留白间隔
            Padding(padding: const EdgeInsets.only(top: 10)),

            // 圆形进度条直径指定为100
            SizedBox(
              height: 100,
              width: 100,
              child: CircularProgressIndicator(
                backgroundColor: Colors.grey[200],
                valueColor: AlwaysStoppedAnimation(Colors.blue),
                value: .7,
              ),
            ),

            // 仅作为留白间隔
            Padding(padding: const EdgeInsets.only(top: 10)),

            // 模糊进度条(会执行一个旋转动画)
            CircularProgressIndicator(
              backgroundColor: Colors.grey[200],
              valueColor: AlwaysStoppedAnimation(Colors.blue),
            ),

            // 仅作为留白间隔
            Padding(padding: const EdgeInsets.only(top: 10)),

            //进度条显示50%，会显示一个半圆
            CircularProgressIndicator(
              backgroundColor: Colors.grey[200],
              valueColor: AlwaysStoppedAnimation(Colors.blue),
              value: .5,
            ),

            // 仅作为留白间隔
            Padding(padding: const EdgeInsets.only(top: 10)),

            // 模糊进度条(会执行一个动画)
            LinearProgressIndicator(
              backgroundColor: Colors.grey[200],
              valueColor: AlwaysStoppedAnimation(Colors.blue),
            ),

            // 仅作为留白间隔
            Padding(padding: const EdgeInsets.only(top: 10)),

            //进度条显示50%
            LinearProgressIndicator(
              backgroundColor: Colors.grey[200],
              valueColor: AlwaysStoppedAnimation(Colors.blue),
              value: .5,
            ),
          ],
        ),
      ),
    );
  }

}